package com.crm.web.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.crm.common.core.controller.BaseController;
import com.crm.common.core.domain.AjaxResult;
import com.crm.common.core.domain.entity.SysUser;
import com.crm.framework.shiro.service.SysRegisterService;
import com.crm.system.service.ISysConfigService;
import java.util.Map;

/**
 * 注册验证
 * 
 * @author crm
 */
@Controller
public class SysRegisterController extends BaseController
{
    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private ISysConfigService configService;

    @GetMapping("/register")
    public String register()
    {
        return "register";
    }

    @PostMapping("/register")
    @ResponseBody
    public AjaxResult ajaxRegister(SysUser user)
    {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
        {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }

    @PostMapping("/registerDoctor/{uuid}")
    @ResponseBody
    public AjaxResult registerDoctor(@PathVariable String uuid){
//        String uuid=map.get("uuid");
//        System.out.println(uuid);
//        try{
//        String msg = registerService.registerDoctor(uuid);
//        System.out.println(msg);
//        return success();
//        }
//        catch (Exception e){
//            e.printStackTrace();
//            return error(e.getMessage());
//        }
        String msg = registerService.registerDoctor(uuid);
       // System.out.println(msg);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }

    @PostMapping("/registerPatient/{uuid}")
    @ResponseBody
    public AjaxResult registerPatient(@PathVariable String uuid){
//        String uuid=map.get("uuid");
//        System.out.println(uuid);
        String msg = registerService.registerPatient(uuid);
        //System.out.println(uuid);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
